package com.example.recyclerview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;

import com.example.text.CustomLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

    private List<Bean> data =new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        for (int i=0;i<100;i++){
            Bean bean =new Bean();
            bean.setName("享学"+i);
            data.add(bean);
            Log.e("leo","position"+i);
            System.out.println("i==>"+i);

            RecyclerView recyclerView=findViewById(R.id.rv);
            //以下两条语句设置线性布局
            //LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
            /*LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false);  //横向
            recyclerView.setLayoutManager(linearLayoutManager);*/

            //设置网格布局
         /*   GridLayoutManager gridLayoutManager=new GridLayoutManager(this,3,RecyclerView.HORIZONTAL,false);
            recyclerView.setLayoutManager(gridLayoutManager);*/

           /* //设置瀑布流布局
            StaggeredGridLayoutManager staggeredGridLayoutManager=new StaggeredGridLayoutManager(3
                    , LinearLayout.VERTICAL);
            recyclerView.setLayoutManager(staggeredGridLayoutManager);
            */


                //自定义重叠LayoutManager  记得指定recyclerView的高度与宽度
            OverFlyingLayoutManager overFlyingLayoutManager=new OverFlyingLayoutManager(OrientationHelper.VERTICAL,true);
            recyclerView.setLayoutManager(overFlyingLayoutManager);

            MyAdapter myAdapter= new MyAdapter(data,this);
            recyclerView.setAdapter(myAdapter);



            myAdapter.setRecyclerItemClickListener(new MyAdapter.OnRecyclerItemClickListener() {
                @Override
                public void onRecyclerItemClick(int position) {
                    Log.e("leo","onRecyclerItemClick"+position);
                   // recyclerView.setScrollingTouchSlop();
                    recyclerView.smoothScrollToPosition(0);

                }
            });
        }
    }
}